﻿package  
{
	import com.kerry.camera.CameraTracer;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.transitions.Tween;
	import fl.transitions.easing.None;
	import fl.transitions.TweenEvent;
	/**
	 * com.kerry.camera.CameraTracer 类的演示文件
	 * @author PhoenixKerry（http://blog.sina.com.cn/yyy98）
	 */
	public class Main extends MovieClip {
		private var ballTracer:CameraTracer;
		private var ball:MovieClip;
		
		private var ballTweenX:Tween;
		private var ballTweenY:Tween;
		
		public function Main() {
			ball = gamelevel_mc.ball_mc;
			
			// 设置镜头追踪小球
			ballTracer = new CameraTracer(ball, ball.parent, stage.stageWidth, stage.stageHeight);
			addEventListener(Event.ENTER_FRAME, tracingBall);
			
			// 设置小球随机运动 X，Y坐标
			changeRandPosX(null);
			changeRandPosY(null);
		}
		
		/**
		 * 让镜头跟踪
		 * @param	e
		 */
		private function tracingBall(e:Event):void {
			ballTracer.xTrace();
			ballTracer.yTrace();
		}
		
		// 随即小球 X 轴
		private function changeRandPosX(e:TweenEvent):void  {
			ballTweenX = new Tween(ball, "x", None.easeNone, ball.x, Math.random() * ball.parent.width, 2, true);
			ballTweenX.addEventListener(TweenEvent.MOTION_FINISH, changeRandPosX);
		}
		
		// 随即小球 Y 轴
		private function changeRandPosY(e:TweenEvent):void  {
			ballTweenY = new Tween(ball, "y", None.easeNone, ball.y, Math.random() * ball.parent.height, 2, true);
			ballTweenY.addEventListener(TweenEvent.MOTION_FINISH, changeRandPosY);
		}
	}

}